<template>
  <div class="shopwrap">
       <div class="top" ref='top'></div>
       <div class="shoplist" >
          <ul>
            <li v-for="(item,index) in shopList" :key="item.cateId" :class="{'current':currentIndex==index}" @click="getShopListItem(index)">
              {{item.cateName}}
            </li>
          </ul>
       </div>
       <div class="shopcontent">
        <ul>
          <li v-for="(items,index) in shopList" 
              :key="items.cateId" 
              v-if="items.list" 
              ref="listGroup"
              :id="'anchor-'+index"> 
             <p>{{items.cateName}}</p>
             <div class="shopPic">
               <ul>
                 <li v-for="item in items.list" :key="item.cateId" @click="goGoodsList(item.cateId)">
                   <div class="pic">
                     <img :src="item.cateIcon" alt="">
                   </div>
                   <p>{{item.cateName}}</p>
                 </li>
               </ul>
             </div>
          </li>
        </ul>
       </div>
  </div>
</template>

<script>
const LISTHIGHT = 50;
export default {
  data() {
    return {
      shopList: [],
      currentIndex: 0,
      listHeight: []
    };
  },
  created() {},
  mounted() {
    this.$nextTick(() => {
      this.getShopList();
      //  this.getShopListHeight();
    });
  },
  methods: {
    getShopList() {
      this.$axios
        .get(process.env.baseUrl + "/web-avicare-1.0/weixin/mall/findmdsecate")
        .then(res => {
          this.shopList = res.data.list;
        })
        .catch(error => {
          console.log(error);
        });
    },
    getShopListItem(index) {
      this.currentIndex = index;
      let anchor = this.$el.querySelector("#anchor-" + index);
      if (anchor) {
        document.body.scrollTop = anchor.offsetTop - this.$refs.top.offsetHeight;
      }
    },
    goGoodsList(id){
     this.$router.push({
       name:'goodsList',
       query:{id:id,shopName:'afk_mall'}
     })
    },
    getShopListHeight() {
      this.listHeight = [];
      const list = this.$refs.listGroup;
      let height = 0;
      this.listHeight.push(height);
      for (let i = 0; i < list.length; i++) {
        let item = list[i];
        height += item.clientHeight;
        this.listHeight.push(height);
      }
    }
  }
};
</script>

<style lang="less" scoped>
.shopwrap {
  width: 100%;
  height: auto;
  overflow: hidden;
  background-color: #f7f7f7;
  padding-top: 0.95rem;
  .top {
    width: 100%;
    height: 0.9rem;
    position: fixed;
    top: 0;
    left: 0;
    background: #fff;
    z-index: 99;
  }
  .shoplist {
    position: fixed;
    top: 0.95rem;
    left: 0;
    ul {
      width: 1.8rem;
      background: #ccc;
      li {
        width: 100%;
        float: left;
        font-size: 0.26rem;
        height: 1rem;
        line-height: 1rem;
        text-align: center;
        color: #232323;
        list-style: none;
        border-bottom: 1px solid #f7f7f7;
        box-sizing: border-box;
        background-color: #fff;
      }
      .current {
        background-color: #f7f7f7;
        border-left: 2px solid #78bfff;
      }
    }
  }
  .shopcontent {
    width: 5.3rem;
    margin-left: 2rem;
    ul {
      width: 100%;
      li {
        width: 100%;
        list-style: none;
        p {
          color: #232323;
          font-size: 0.26rem;
          text-align: left;
          font-weight: 700;
          margin-bottom: 0.09rem;
          padding-top: 0.2rem;
        }
        .shopPic {
          ul {
            width: 100%;
            padding: 0.3rem 0.3rem 0;
            overflow: hidden;
            box-sizing: border-box;
            background-color: #fff;
            li {
              list-style: none;
              width: 1.2rem;
              float: left;
              margin-right: 0.55rem;
              &:nth-child(3n) {
                margin-right: 0;
              }
              .pic {
                width: 1.2rem;
                height: 1.2rem;
                img {
                  width: 100%;
                  height: 100%;
                }
              }
              p {
                font-size: 0.26rem;
                color: #232323;
                text-align: center;
                margin-top: 0.1rem;
                margin-bottom: 0.2rem;
              }
            }
          }
        }
      }
    }
  }
}
</style>
